package com.et.sale.user.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import com.et.sale.user.entity.UserEntity;
import com.et.sale.user.service.UserService;

@Service
@RequestMapping("/user")
public class UserController {
	
	
	
	@Autowired
	private UserService service;
	
	
	@RequestMapping("/login")
	public String login(UserEntity entity,HttpServletRequest request){
		
		//1 把页面穿过的userName 和 密码 和 表的比较  看是否一致  
		//如果相同 表示登录成功  否则 提示 用户名或密码错误
		
		if(null != entity && null != entity.getPhone() && null != entity.getPassword()){ //入参数检测
			UserEntity dbEntity  = service.login(entity);
			if(null == dbEntity ){
				return "user/error";
			}else{
				if(entity.getPhone().equals(dbEntity.getPhone()) && entity.getPassword().equals(dbEntity.getPassword())){
					//如果相同 表示登录成功
					request.getSession().setAttribute("userId", dbEntity.getId());
					return "forward:/ticket/list.do";
				}else{
					//否则 提示 用户名或密码错误
					return "user/error";
				}
				
			}
		}else{
			return "user/error";
		}
		
		
		
		
		
	}
	
	
	

}
